package com.song.helper.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.song.helper.model.Address;
import com.song.helper.service.IAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author stylefeng
 * @since 2018-02-27
 */
@Controller
@RequestMapping("/address")
public class AddressController {
    private final String PREFIX = "/song/address/";

    @Autowired
    private IAddressService addressService;

    @RequestMapping("")
    public String index(){
        return PREFIX+"address.html";
    }
    @ResponseBody
    @RequestMapping("/list")
    public Map list(@RequestParam("current") Integer current ,
                    @RequestParam("rowCount") Integer rowCount  ){
        Page<Address> pageParam = new Page<>(current,rowCount);
        Page<Address> page = addressService.selectPage(pageParam);
        HashMap<String, Object> map = new HashMap<>();
        map.put("current",current);
        map.put("rowCount",rowCount);
        map.put("total",page.getTotal());
        map.put("rows",page.getRecords());
        return map;
    }

}
